namespace EntityKit.Runtime
{
    /// <summary>
    /// StorageKit配置类
    /// </summary>
    public class StorageKitConfig
    {
        public string StorageSubPath { get; set; }
        public IDataSerializer Serializer { get; set; }
        public IEncryptionProvider EncryptionProvider { get; set; }
        public IPlatformStorageAdapter PlatformAdapter { get; set; }
        
        /// <summary>
        /// 默认构造函数
        /// </summary>
        public StorageKitConfig()
        {
            StorageSubPath = "";
            Serializer = new JsonDataSerializer();
            EncryptionProvider = new NullEncryptionProvider();
            PlatformAdapter = new DefaultPlatformStorageAdapter();
        }
        
        /// <summary>
        /// 使用存储子路径初始化配置
        /// </summary>
        /// <param name="storageSubPath">存储子路径</param>
        public StorageKitConfig(string storageSubPath)
        {
            StorageSubPath = storageSubPath;
            Serializer = new JsonDataSerializer();
            EncryptionProvider = new NullEncryptionProvider();
            PlatformAdapter = new DefaultPlatformStorageAdapter();
        }
        
        /// <summary>
        /// 使用存储子路径和序列化器初始化配置
        /// </summary>
        /// <param name="storageSubPath">存储子路径</param>
        /// <param name="serializer">数据序列化器</param>
        public StorageKitConfig(string storageSubPath, IDataSerializer serializer)
        {
            StorageSubPath = storageSubPath;
            Serializer = serializer;
            EncryptionProvider = new NullEncryptionProvider();
            PlatformAdapter = new DefaultPlatformStorageAdapter();
        }
        
        /// <summary>
        /// 使用存储子路径、序列化器和加密提供者初始化配置
        /// </summary>
        /// <param name="storageSubPath">存储子路径</param>
        /// <param name="serializer">数据序列化器</param>
        /// <param name="encryptionProvider">加密提供者</param>
        public StorageKitConfig(string storageSubPath, IDataSerializer serializer, IEncryptionProvider encryptionProvider)
        {
            StorageSubPath = storageSubPath;
            Serializer = serializer;
            EncryptionProvider = encryptionProvider;
            PlatformAdapter = new DefaultPlatformStorageAdapter();
        }
        
        /// <summary>
        /// 使用所有参数初始化配置
        /// </summary>
        /// <param name="storageSubPath">存储子路径</param>
        /// <param name="serializer">数据序列化器</param>
        /// <param name="encryptionProvider">加密提供者</param>
        /// <param name="platformAdapter">平台适配器</param>
        public StorageKitConfig(string storageSubPath, IDataSerializer serializer, IEncryptionProvider encryptionProvider, IPlatformStorageAdapter platformAdapter)
        {
            StorageSubPath = storageSubPath;
            Serializer = serializer;
            EncryptionProvider = encryptionProvider;
            PlatformAdapter = platformAdapter;
        }
        
        /// <summary>
        /// 验证配置是否有效
        /// </summary>
        public bool Validate()
        {
            return !string.IsNullOrEmpty(StorageSubPath) && Serializer != null && EncryptionProvider != null && PlatformAdapter != null;
        }
    }
}